package com.rules.admin.expression;

import com.google.common.base.Joiner;
import com.google.common.collect.Lists;

import java.util.List;

public class ElseIfExpression implements Expression {
   private Expression condition;
   private List<Expression> executeExpressions = Lists.newArrayList();

   public void accept(ExpressionVisitor visitor) {
   }

   public void addExecuteExpression(Expression expression) {
      this.executeExpressions.add(expression);
   }

   public Expression getCondition() {
      return this.condition;
   }

   public void setCondition(Expression condition) {
      this.condition = condition;
   }

   public List<Expression> getExecuteExpressions() {
      return this.executeExpressions;
   }

   public void setExecuteExpressions(List<Expression> executeExpressions) {
      this.executeExpressions = executeExpressions;
   }

   public String toString() {
      StringBuilder builder = new StringBuilder();
      builder.append("else if(").append(this.condition).append(")").append("{\n").append(Joiner.on(";\n").join(this.executeExpressions).replaceAll("\\n", "\\\n\t")).append(";\n").append("\n}");
      return builder.toString();
   }
}
